import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { ModDataButton, DelDataButton, CommonButton } from '../Common/options'
import { OrganizationIdentityLevel, ProjectBuildingPaymentItem } from '../Common/Conversion'

export const ProjectBuildingPaymentStat = async ({ url, OptionsEvent, Permission, actionRef }) => {
    const OrgList = await OrganizationIdentityLevel(4)
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'createTime@desc' },
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === '06ebd38f-ba4b-4e0f-967f-e911f1f778f8') !== -1 && (
                // <ProjectBuildingPaymentStatButton OptionsEvent={OptionsEvent} url={url} title="新增" />
                <CommonButton
                    key="RichText"
                    OptionsEvent={OptionsEvent}
                    title="新增"
                    type="primary"
                    icon="add"
                    data={{
                        smallTitle: `添加资金实际支付`,
                        type: 'BadaBatchAdd',
                        dataType: 0,
                        actionRef,
                        OrgList,
                    }}
                />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, rules: true },
            { ...commonTableList.code, rules: true, hideInSearch: true },
            {
                dataIndex: 'organizationUuid',
                title: '组织机构',
                valueType: 'select',
                valueEnum: OrgList,
                ellipsis: true,
                width: 450,
                rules: true,
            },
            {
                dataIndex: 'projectBuildingPaymentItemUuid',
                title: '清单项',
                valueType: 'select',
                valueEnum: await ProjectBuildingPaymentItem(),
                hideInSearch: true,
                width: 300,
                rules: true,
            },

            {
                dataIndex: 'projectBuildingPaymentItem',
                title: '类型',
                valueType: 'input',
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, e) => (
                    <div>
                        {
                            BuiltInData.projectBuildingPaymentType[
                                e.projectBuildingPaymentItem.projectBuildingPaymentType
                            ]
                        }
                    </div>
                ),
                width: 300,
                rules: true,
            },

            {
                dataIndex: 'amount',
                title: '金额(万元)',
                valueType: 'inputNumber',
                hideInSearch: true,
                width: 200,
                rules: true,
            },
            {
                dataIndex: 'actualDate',
                title: '日期',
                valueType: 'Date',
                hideInSearch: true,
                showTime: true,
                width: 200,
                rules: true,
            },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 150,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === 'c62280f3-b0f8-4fd6-958a-7e85a55bc960') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        Permission.findIndex(v => v.uuid === '2f2abf01-d53a-4296-8951-c39723594fe8') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    // const apiData = await axios.get(API_LIST()['getProjectBuildingPaymentItem'])
    // const { list } = apiData.data
    // let selectData = {}
    // list.forEach(({ uuid, code, tableName }) => Object.assign(selectData, { [uuid]: `${code} ${tableName}` }))
    // data.columns.find(v => v.dataIndex === 'projectBuildingPaymentItemUuid').valueEnum = selectData
    return data
}
